//
//  PGTagCell.m
//  youqu
//
//  Created by 彭鹏 on 16/9/16.
//  Copyright © 2016年 pengpeng. All rights reserved.
//

#import "PGTagCell.h"
#import "PGTagItem.h"
#import <SDWebImage/UIImageView+WebCache.h>
#import <Photos/Photos.h>

@interface PGTagCell ()
@property (weak, nonatomic) IBOutlet UIImageView *image_listImageView;
@property (weak, nonatomic) IBOutlet UILabel *theme_nameLabel;
@property (weak, nonatomic) IBOutlet UILabel *sub_numberLabel;

@end

@implementation PGTagCell



- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
    }
    
    return self;
}

-(void)awakeFromNib {
    [super awakeFromNib];
    

}

- (void)setTagItem:(PGTagItem *)tagItem {
    _tagItem = tagItem;
    [self.image_listImageView sd_setImageWithURL:[NSURL URLWithString:tagItem.image_list] placeholderImage:[UIImage imageNamed:@"defaultUserIcon"] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
        
        if (image == nil) return;
        self.image_listImageView.image = [image imageCicle:image];
        
//        //1.开启图形上下文
////        UIGraphicsBeginImageContext(image.size);
//        UIGraphicsBeginImageContextWithOptions(image.size, NO, 0);
//        
//        //2.描述圆形裁剪区域
//        UIBezierPath *bezierPath = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, image.size.width, image.size.height)];
//        
//        //3.添加裁剪区域
//        [bezierPath addClip];
//        
//        //4.将图片滑到裁剪区域上
//        [image drawAtPoint:CGPointZero];
//        
//        //5.获取图片
//        image = UIGraphicsGetImageFromCurrentImageContext();
//        
//        //6.关闭图形上下文
//        UIGraphicsEndImageContext();
//        
//        self.image_listImageView.image = image;
        
    }];
    
    self.theme_nameLabel.text = tagItem.theme_name;
    
    
    NSInteger sub_number = [tagItem.sub_number integerValue];
    sub_number = 10000;
    
    if (sub_number >= 10000) {
        self.sub_numberLabel.text = [NSString stringWithFormat:@"%.1f万人订阅",sub_number/10000.0];
        self.sub_numberLabel.text = [self.sub_numberLabel.text stringByReplacingOccurrencesOfString:@".0" withString:@""];
    }else {
//        sel/Users/pengpeng/Documents/youqu/youqu/youquf.sub_numberLabel.
        
        self.sub_numberLabel.text = [NSString stringWithFormat:@"%zd人订阅",sub_number];
    }

}

//- (void)setFrame:(CGRect)frame {
//    frame.size.height -= 1;
//    [super setFrame:frame];
//}

- (void)layoutSubviews {
    [super layoutSubviews];
    UIView *separatorView = [[UIView alloc] initWithFrame:CGRectMake(0, self.pg_height-1, SCREENW, 1)];
    separatorView.backgroundColor = [UIColor redColor];
    [self addSubview:separatorView];
}



- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
